#!/bin/bash

#Options:
#Total job's
#Pre-processing
#Decision
#Conflict analyzing
#Backtracking
#Structures reset
#Creating structures
#Next job
#Add jobs to assumptions
#Processing results
#Pre-processing - handling assumptions
#Pre-processing - adding assumptions to graph
#Pre-processing - adding handling variables

STATS_TYPE=none
TOTAL_AVERAGE=none

FILE=$1

TYPE_GOAL=$2

OUTPUT_FILE_PREFIX=statistics_output/$FILE
OUTPUT_FILE_SUFFIX=_stats.csv

case $TYPE_GOAL in
1) STATS_TYPE_GOAL="Total job's"
;;
2) STATS_TYPE_GOAL="Pre-processing"
;;
3) STATS_TYPE_GOAL="Decision"
;;
4) STATS_TYPE_GOAL="Conflict analyzing"
;;
5) STATS_TYPE_GOAL="Backtracking"
;;
6) STATS_TYPE_GOAL="Structures reset"
;;
7) STATS_TYPE_GOAL="Creating structures"
;;
8) STATS_TYPE_GOAL="Next job"
;;
9) STATS_TYPE_GOAL="Add jobs to assumptions"
;;
10) STATS_TYPE_GOAL="Processing results"
;;
11) STATS_TYPE_GOAL="Pre-processing - handling assumptions"
;;
12) STATS_TYPE_GOAL="Pre-processing - adding assumptions to graph"
;;
13) STATS_TYPE_GOAL="Pre-processing - adding handling variables"
;;
*) echo "Unknown option"
exit 1;

esac

echo $STATS_TYPE_GOAL

while read line
do

	if [[ $line =~ ^"File = " ]] || [[ $line =~ ^"Blocks = "[0-9]+$ ]] || [[ $line =~ ^"Threads = "[0-9]+$ ]] || [[ $line =~ ^"Number of jobs = "[0-9]+$ ]]
	then
		echo $line
	fi


	if [[ "$line" =~ "Total job's time:" ]] || [[ "$line" =~ "Pre-processing time:" ]] || [[ "$line" =~ "Decision time:" ]] || [[ "$line" =~ "Conflict analyzing time:" ]] || [[ "$line" =~ "Backtracking time:" ]] || [[ "$line" =~ "Structures reset time:" ]] || [[ "$line" =~ "Creating structures time:" ]] || [[ "$line" =~ "Next job time:" ]] || [[ "$line" =~ "Add jobs to assumptions time:" ]] || [[ "$line" =~ "Processing results time:" ]] || [[ "$line" =~ "Pre-processing - handling assumptions time:" ]] || [[ "$line" =~ "Pre-processing - adding assumptions to graph time:" ]] || [[ "$line" =~ "Pre-processing - adding handling variables time:" ]]
	then
		STATS_TYPE=`echo "$line" | sed 's/ time://g'`
#		echo $STATS_TYPE
	fi
#Total:
#Average:

	if [[ "$line" =~ "Total:" ]] || [[ "$line" =~ "Average:" ]]
	then
		TOTAL_AVERAGE=`echo "$line" | sed 's/://g'`
	fi

#	Block 0, thread 0: 77052326971392.000
	if [[ "$line" =~ "Block "[0-9]+", thread "[0-9]+": "[0-9]+(".")?[0-9]* ]]
	then
		if [[ "$STATS_TYPE" == "$STATS_TYPE_GOAL" ]] && [[ "$TOTAL_AVERAGE" == "Total" ]]
		then
			FILE_NAME=
			echo $line | cut -d " " -f 5 | sed s/","//g
		fi

	fi

	if [[ "$line" =~ "Block "[0-9]+", thread "[0-9]+": not run" ]]
	then

		if [[ "$STATS_TYPE" == "$STATS_TYPE_GOAL" ]] && [[ "$TOTAL_AVERAGE" == "Total" ]]
		then
			echo "0"
		fi

	fi

done < $FILE
